package neca.tmazo.vista.vistaGUI;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;

import neca.tmazo.datasets.Dataset;
import neca.tmazo.modelo.WindowEventListener;
import neca.tmazo.vista.WindowItems;

/**
 * 
 * @author neca
 *
 */
public class VentanaFormularioRegistro extends JPanel {

	/**
	 * Crea el panel para la ventana de la cancion.
	 * @param observer 
	 */
	private ListaMusica listaMusica=null;
	private JTextField txtUser;
	private JTextField txtEmail;
	private JPasswordField txtPass;
	private JPasswordField txtPassRep;
	
	public VentanaFormularioRegistro(final WindowEventListener observer) {
		setBackground(Color.DARK_GRAY);
		setSize(new Dimension(750, 500));
		setBounds(new Rectangle(0, 0, 750, 500));
		setLayout(null);
		
		final JComboBox comboBox = new JComboBox();
		comboBox.setBackground(Color.WHITE);
		comboBox.setToolTipText("");
		comboBox.setFont(new Font("Tahoma", Font.PLAIN, 11));
		comboBox.setBounds(465, 385, 150, 30);
		add(comboBox);
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"Regular", "Artista"}));
		comboBox.setSelectedIndex(0);
		
		txtUser = new JTextField();
		txtUser.setFont(new Font("Tahoma", Font.PLAIN, 11));
		txtUser.setBounds(375, 140, 350, 30);
		add(txtUser);
		txtUser.setColumns(10);
		
		txtEmail = new JTextField();
		txtEmail.setFont(new Font("Tahoma", Font.PLAIN, 11));
		txtEmail.setColumns(10);
		txtEmail.setBounds(375, 205, 350, 30);
		add(txtEmail);
		
		txtPass = new JPasswordField();
		txtPass.setFont(new Font("Tahoma", Font.PLAIN, 11));
		txtPass.setColumns(10);
		txtPass.setBounds(375, 270, 350, 30);
		add(txtPass);
		
		txtPassRep = new JPasswordField();
		txtPassRep.setFont(new Font("Tahoma", Font.PLAIN, 11));
		txtPassRep.setColumns(10);
		txtPassRep.setBounds(375, 335, 350, 30);
		add(txtPassRep);
		
		JButton btnNewButton = new JButton("Guardar");
		btnNewButton.setBackground(Color.DARK_GRAY);
		btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnNewButton.setBounds(465, 438, 150, 40);
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				Dataset ds=new Dataset();
				ds.add(WindowItems.FORMULARIOREGISTRO_FORMULARIO_EMAIL, txtEmail.getText());
				ds.add(WindowItems.FORMULARIOREGISTRO_FORMULARIO_NOMBRE, txtUser.getText());
				ds.add(WindowItems.FORMULARIOREGISTRO_FORMULARIO_PASS, txtPass.getText());
				ds.add(WindowItems.FORMULARIOREGISTRO_FORMULARIO_PASSREPETIDA, txtPassRep.getText());
				String tipoUser=comboBox.getSelectedIndex()==0?WindowItems.USUARIO_TIPO_NORMAL+"" : WindowItems.USUARIO_TIPO_ARTISTA+"";
				ds.add(WindowItems.FORMULARIOREGISTRO_FORMULARIO_TIPOUSUARIO, tipoUser);
				
				observer.onMenuItemSelected(WindowItems.FORMULARIOREGISTRO_BOTON_GUARDAR, ds);
			}
		});
		add(btnNewButton);
		
		JTextPane txtpnMiRecopilatorio = new JTextPane();
		txtpnMiRecopilatorio.setForeground(Color.LIGHT_GRAY);
		txtpnMiRecopilatorio.setBounds(30, 25, 436, 45);
		add(txtpnMiRecopilatorio);
		txtpnMiRecopilatorio.setEditable(false);
		txtpnMiRecopilatorio.setBackground(Color.DARK_GRAY);
		txtpnMiRecopilatorio.setFont(new Font("Dialog", Font.BOLD, 30));
		txtpnMiRecopilatorio.setText("Formulario de Registro\r\n");
		
		JButton btnAtras = new JButton("Atras");
		btnAtras.setBackground(Color.DARK_GRAY);
		btnAtras.setBounds(600, 30, 120, 40);
		add(btnAtras);
		btnAtras.setFont(new Font("Tahoma", Font.PLAIN, 11));
		
		JLabel txtpnUser = new JLabel("Nombre de usuario");
		txtpnUser.setForeground(Color.LIGHT_GRAY);
		txtpnUser.setBounds(375, 115, 108, 14);
		add(txtpnUser);
		
		JLabel txtpnEmail = new JLabel("Correo electr\u00F3nico");
		txtpnEmail.setForeground(Color.LIGHT_GRAY);
		txtpnEmail.setBounds(375, 180, 132, 14);
		add(txtpnEmail);
		
		JLabel txtpnPass = new JLabel("Contrase\u00F1a");
		txtpnPass.setForeground(Color.LIGHT_GRAY);
		txtpnPass.setBounds(375, 245, 108, 14);
		add(txtpnPass);
		
		JLabel txtpnPassRep = new JLabel("Repita contrase\u00F1a");
		txtpnPassRep.setForeground(Color.LIGHT_GRAY);
		txtpnPassRep.setBounds(375, 310, 108, 14);
		add(txtpnPassRep);
		
		JLabel txtpnRegWelcome = new JLabel("Te estabamos esperando");
		txtpnRegWelcome.setForeground(Color.LIGHT_GRAY);
		txtpnRegWelcome.setFont(new Font("Tahoma", Font.PLAIN, 16));
		txtpnRegWelcome.setBounds(94, 331, 176, 40);
		add(txtpnRegWelcome);
		
		ImageIcon logo = ImageManager.getImage(ImageManager.IMAGE_LOGO_TMAZO_LOGIN);
		JLabel Logo = new JLabel(logo);
		Logo.setHorizontalAlignment(SwingConstants.CENTER);
		Logo.setBounds(56, 160, 250, 140);
		add(Logo);
		
		btnAtras.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				observer.onMenuItemSelected(WindowItems.FORMULARIOREGISTRO_BOTON_ATRAS, null);
			}
		});
		
	}
	public static void main(String[] args)
	{
		final Ventana v=new Ventana();
		v.mostrar(new VentanaFormularioRegistro(null));
	}
}
